<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise简写之盒子定时器</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>

    <script>
        var boxs = document.querySelectorAll('.box');
        
        // 第一个
        var promise = new Promise((resolve,reject)=>{
            setTimeout(()=>{
                boxs[0].style.background = 'pink';
                resolve();
            },1000)
        // 第二个
        }).then(()=>{
            return new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    boxs[1].style.background = 'red';
                    resolve();
                },1000)
            })
        // 第三个
        }).then(()=>{
            return new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    boxs[2].style.background = 'blue';
                    resolve();
                },1000)
            })
        // 第四个
        }).then(()=>{
            return new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    boxs[3].style.background = 'green';
                    resolve();
                },1000)
            })
        // 第五个
        }).then(()=>{
            return new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    boxs[4].style.background = 'orange';
                },1000)
            })
        })

    </script>
</body>
</html>